package com.atguigu.tingshu.album.api;

import com.atguigu.tingshu.album.service.AlbumAttributeValueService;
import com.atguigu.tingshu.album.service.AlbumInfoService;
import com.atguigu.tingshu.album.service.TrackInfoService;
import com.atguigu.tingshu.common.anno.GuiGuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.common.result.ResultCodeEnum;
import com.atguigu.tingshu.model.album.AlbumAttributeValue;
import com.atguigu.tingshu.model.album.AlbumInfo;
import com.atguigu.tingshu.model.album.TrackInfo;
import com.atguigu.tingshu.query.album.AlbumInfoQuery;
import com.atguigu.tingshu.vo.album.AlbumInfoVo;
import com.atguigu.tingshu.vo.album.AlbumListVo;
import com.atguigu.tingshu.vo.album.AlbumStatVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@Tag(name = "专辑管理")
@RestController
@RequestMapping("api/album/albumInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class AlbumInfoApiController {

	private final AlbumInfoService albumInfoService;

	private final AlbumAttributeValueService albumAttributeValueService ;

	private final TrackInfoService trackInfoService;
	@Autowired
	public AlbumInfoApiController(AlbumInfoService albumInfoService, AlbumAttributeValueService albumAttributeValueService, TrackInfoService trackInfoService) {
		this.albumInfoService = albumInfoService;
		this.albumAttributeValueService = albumAttributeValueService;
		this.trackInfoService = trackInfoService;
	}
	/**
	 * @description: 新增专辑信息
	 * @author Petrichor
	 * @date 2023/12/21 19:42
	 * @param albumInfo 前端传来的专辑信息
	 * @return NULL
	**/
	@GuiGuLogin
	@PostMapping("/saveAlbumInfo")
	public Result saveAlbumInfo(@RequestBody AlbumInfo albumInfo){
		albumInfoService.saveAlbumInfo(albumInfo);
		return Result.ok();
	}
	/**
	 * @description:  查询当前用户专辑分页列表
	 * @author Petrichor
	 * @date 2023/12/21 20:30
	 * @param page 当前页数
	 * @param limit 当前页面的条数
	 * @param albumInfoQuery 待条件查询
	 * @return 分页 Page 对象
	 **/
	@GuiGuLogin
	@PostMapping("/findUserAlbumPage/{page}/{limit}")
	public Result<IPage<AlbumListVo>> findByPage(
			@PathVariable(value = "page")Integer page,
			@PathVariable(value = "limit")Integer limit,
			@RequestBody AlbumInfoQuery albumInfoQuery) {
		IPage<AlbumListVo> albumListVoIPage = albumInfoService.findByPage(page , limit , albumInfoQuery) ;
		return Result.build(albumListVoIPage , ResultCodeEnum.SUCCESS);
	}
	/**
	 * @description: 根据专辑 id删除专辑
	 * @author Petrichor
	 * @date 2023/12/21 21:20
	 * @param id 专辑id
	 * @return NULL
	**/
	@DeleteMapping("/removeAlbumInfo/{id}")
	public Result removeAlbumInfo(@PathVariable Long id){
		albumInfoService.removeAlbumInfoById(id);
		return Result.ok();
	}
	/**
	 * @description: 根据id获取专辑
	 * @author Petrichor
	 * @date 2023/12/21 22:41
	 * @param id 专辑id
	 * @return  AlbumInfo 返回专辑信息
	**/
	@GetMapping("/getAlbumInfo/{id}")
	public Result<AlbumInfo> getAlbumInfo(@PathVariable(value = "id") Long id){
		AlbumInfo albumInfo = albumInfoService.getAlbumInfo(id);
		return Result.ok(albumInfo);
	}
	/**
	 * @description: 根据id修改专辑
	 * @author Petrichor
	 * @date 2023/12/21 22:53
	 * @param id 专辑id
	 * @return NULL
	**/
	@PutMapping("/updateAlbumInfo/{id}")
	public Result updateAlbumInfo(@PathVariable(value = "id") Long id,@RequestBody @Validated AlbumInfoVo albumInfoVo){
		albumInfoService.updateAlbumInfo(id,albumInfoVo);
		return Result.ok();
	}





	/**
	 * @description: 获取当前用户全部专辑列表
	 * @author Petrichor
	 * @date 2023/12/22 16:17
	 * @return AlbumInfo
	**/
	@GuiGuLogin
	@GetMapping("/findUserAllAlbumList")
	public Result<List<AlbumInfo>> findUserAllAlbumList(){
     	return Result.ok(albumInfoService.findUserAllAlbumList());
	}


	/**
	 * @description: 根据专辑id查询专辑属性值
	 * @author Petrichor
	 * @date 2023/12/26 20:18
	 * @param albumId 专辑id
	 * @return  AlbumAttributeValue 专辑属性值
	**/
	@Operation(summary = "根据专辑id查询专辑属性值")
	@GetMapping(value = "/findAlbumAttributeValue/{albumId}")
	public Result<List<AlbumAttributeValue>> findAlbumAttributeValueByAlbumId(@PathVariable(value = "albumId") Long albumId) {
		List<AlbumAttributeValue> albumAttributeValueList = albumAttributeValueService.findAlbumAttributeValueByAlbumId(albumId) ;
		return Result.ok(albumAttributeValueList) ;
	}
	/**
	 * @description: 根据专辑的id查询专辑的统计数据
	 * @author Petrichor
	 * @date 2023/12/26 21:15
	 * @param albumId 专辑id
	 * @return AlbumStatVo专辑的统计数据
	 **/
	@GetMapping(value = "findAlbumStatByAlbumId/{albumId}")
	public Result<AlbumStatVo> findAlbumStatByAlbumId(@PathVariable(value = "albumId") Long albumId) {
		AlbumStatVo albumStatVo = albumInfoService.findAlbumStatByAlbumId(albumId) ;
		return Result.build(albumStatVo , ResultCodeEnum.SUCCESS) ;
	}
	/**
	 * @description: 批量获取下单付费声音列表
	 * @author Petrichor
	 * @date 2024/1/7 22:28
	 * @param trackId 声音id
	 * @param trackCount 购买集数
	 * @return 购买的声音列表
	**/
	@Operation(summary = "批量获取下单付费声音列表")
	@GetMapping("/findPaidTrackInfoList/{trackId}/{trackCount}")
	public Result<List<TrackInfo>> findPaidTrackInfoList(@PathVariable Long trackId, @PathVariable Integer trackCount) {
		List<TrackInfo> trackInfoList = trackInfoService.findPaidTrackInfoList(trackId, trackCount);
		return Result.ok(trackInfoList);
	}
}

